package com.hz.web.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.hz.web.dao.GsDao;
import com.hz.web.entity.AreaDepartmentEntity;
import com.hz.web.entity.GsHtmlEntity;
import com.hz.web.service.IgsHtmlService;
import com.hz.web.util.Uid;

@Service
public class GsHtmlImpl implements IgsHtmlService {

	@Resource
	private GsDao dao;
	
	
	/**
	 * 修改富文本信息
	 * @param entity
	 * @return
	 */
	@Override
	public int updateGsHtml(GsHtmlEntity entity) {

		return dao.updateGsHtml(entity);
	}
	
	
	/**
	 * 根据富文本类型查询富文本信息
	 */
	@Override
	public List<GsHtmlEntity> queryGsHtml(Map<String, Object> parmsMap) {
		
		return dao.queryGsHtml(parmsMap);
	}
	
	/**
	 * 查询总条数
	 * @param parmsMap
	 * @return
	 */
	@Override
	public int queryGsHtmlCount(Map<String, Object> parmsMap) {
	
		return dao.queryGsHtmlCount(parmsMap);
	}

	/**
	 * 向富文本编辑器中插入数据
	 * @param entity
	 * @return
	 */
	@Override
	public int addGsHtml(GsHtmlEntity entity) {
		entity.setId(Uid.getUid());
		return dao.addGsHtml(entity);
	}

	/**
	 * 根据部门ID查询
	 */
	@Override
	public List<GsHtmlEntity> selectGsHtml(GsHtmlEntity entity, int page,
			int rows) {
		Map<String, Object> parmsMap = new HashMap<String, Object>();
		if(entity!=null){
			parmsMap.put("html", entity.getHtml());
			parmsMap.put("ckType", entity.getCkType());
			parmsMap.put("state", entity.getState());
			parmsMap.put("createTime", entity.getCreateTime());
			parmsMap.put("img", entity.getImg());
			parmsMap.put("title", entity.getTitle());
			parmsMap.put("summary", entity.getSummary());
			parmsMap.put("areaId", entity.getAreaId());
		}
		if(page!=0 && rows!=0){
			int index = (page-1)*rows;
			int end =rows; 
			parmsMap.put("index", index);
			parmsMap.put("end", end);
		}
		List<GsHtmlEntity> ls = dao.selectGsHtml(parmsMap);
		if(ls==null){
			ls = new ArrayList<GsHtmlEntity>();
		}
		return  ls;
	}

	/**
	 * 根据部门ID查询（总数）
	 */
	@Override
	public int selectGsHtmlCount(GsHtmlEntity entity) {
		// TODO Auto-generated method stub
		Map<String, Object> parmsMap = new HashMap<String, Object>();
		if(entity!=null){
			parmsMap.put("areaId", entity.getAreaId());
		}
		return dao.queryGsHtmlCount(parmsMap);
	}

	

}
